<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">仓库名称</label>
            <div class="layui-input-block">
                <input type="text" name="Name" lay-verify="required" lay-reqtext="仓库名称不能为空" placeholder="请输入任务名称"
                    value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">仓库地址</label>
            <div class="layui-input-block">
                <input type="text" name="Addr" lay-verify="required" lay-reqtext="仓库地址不能为空" placeholder="请输入端口映射参数"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">登录用户名</label>
            <div class="layui-input-block">
                <input type="text" name="UserName" lay-verify="required" placeholder="请输入登录用户名" value=""
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">登陆密码</label>
            <div class="layui-input-block">
                <input type="text" name="Password" lay-verify="required" lay-reqtext="登陆密码不能为空" placeholder="请输入登陆密码"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="Remark" class="layui-textarea" placeholder="请输入备注信息"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'

            }, function () {
                // 关闭弹出层
                layer.close(index);
                //layer.close(parentIndex);

            });

            $.ajax({
                url: "/api/store/add",
                data: data.field,
                type: "Post",
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    layer.close(parentIndex);
                    window.parent.location.reload();
                },
                error: function (data) {
                    $.messager.alert('错误', data.msg);
                }
            });
            return false;
        });

    });
</script>